<?php
session_start();

$errore = @$_GET["error"];

if((isset($_SESSION["user"]))&&(isset($_SESSION["type"])))
{
	$user = $_SESSION["user"];
	$tipo = $_SESSION["type"];
	
	if($tipo == "admin")
	{
		header("Location: admin_opt.php");
		exit;
	}
	else
	{
		header("Location: user_opt.php");
		exit;
	}
}

if(isset($_COOKIE["login"]))
{
    foreach($_COOKIE["login"] as $name => $value)
	{
        if($name == "user")
			$user = $value;
		
		if($name == "type")
			$tipo = $value;
    }
	
	if(($user != "")&&($tipo != ""))
	{
		$_SESSION["user"] = $user;
		$_SESSION["type"] = $tipo;
		
		if($tipo == "admin")
		{
			header("Location: admin_opt.php");
			exit;
		}
		else
		{
			header("Location: user_opt.php");
			exit;
		}
	}
}
else
{
	session_unset();
	session_destroy();
}

if($errore == "si")
	$msg = "<tr><td style=\"text-align: center; color: red;\"><b>ATTENZIONE: Username e/o Password errati!</b><br><br></td></tr>\n";
else
	$msg = "";
?>	
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<style type="text/css" media="print">
TD {font-size:11px; font-family="arial,helvetica"}
P {text-indent:-10; text-align="justify"; margin-left:10;}
A:link {color: #44aaaa; text-decoration: underline;}
A:active {color: #000000; text-decoration: underline;}
A:visited {color: #227788; text-decoration: underline;}
A:hover {color: #000000; text-decoration: none; }
BODY {font-size:12px; font-family="arial,helvetica";}
FORM {margin-top:5}
</style>
<style type="text/css" media="screen">
TD {font-size:13px}
P {text-indent:-10; text-align="justify"; margin-left:10;}
A:link {color: #44aaaa; text-decoration: underline;}
A:active {color: #000000; text-decoration: underline;}
A:visited {color: #227788; text-decoration: underline;}
A:hover {color: #000000; text-decoration: none;}
BODY {background-image: url(images/captext.gif); font-size:14px}
FORM {margin-top:5}
</style>
</head>

<body>
<center><font color="#228888" size="4"><br><br><b>BACHECA: LOGIN AREA RISERVATA</b><br><br></font></center>
<center>
<br><br>
<form id="login" name="login" method="post" action="check.php">
	<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="2" cellspacing="2">
		<tr>
			<td style="text-align: center;">
				<img src="images/lucchetto.jpg" alt="lucchetto" width="250px" height="185px">
				<br><br><br><br><br>
				Questa &egrave; un'area <b>riservata</b>. Inserisci <b>username</b> e <b>password</b> nei campi sottostanti:
				<br><br><br>
			</td>
		</tr>
		<tr align="center">
			<?php echo $msg; ?>
			<table width="230px" border="0" cellspacing="0" cellpadding="0">
				<tr>
					<td style="width: 90px; height: 30px;"><b>Username:</b></td>
					<td style="height: 30px;"><input name="username" size="20" maxlength="15" type="text"></td>
				</tr>
				<tr>
					<td style="width: 90px; height: 30px;"><b>Password:</b></td>
					<td style="height: 30px;"><input name="password" size="20" maxlength="6" type="password"></td>
				</tr>
				<tr>
					<td>&nbsp;</td>
					<td style="height: 30px;"><label><input name="rem" type="checkbox" id="rem"> Ricordami!</label></td>
				</tr>
				<tr>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
				</tr>
				<tr>
					<td style="width: 90px;">&nbsp;</td>
					<td align="right"><input name="go" type="submit" id="go" value="Entra"></td>
				</tr>
			</table>
		</tr>
	</table>
</form> 
<br>
<table style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="2" cellspacing="2">
	<tr><td style="vertical-align: middle; text-align: right;"><a href="pubblicati.php">Indietro</a></td></tr>
</table>
</center>
<br>
<table bgcolor="#88CCCC" border="0" cellpadding="1" cellspacing="0" width="100%">
<tr>
	<td> Ultima modifica: <?php echo date("d/m/Y");?></td>
	<td align="right"> Approvato da: Presidente CCdL</td>
</tr>
</table>
</body>
</html>